package app.server.project.main.service.db.entity.user;

import app.server.project.core.constants.Def;
import app.server.project.core.syndb.SynDBMgr;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "user_invite")
@TableName("user_invite")
@Comment(value = "用户邀请信息表")
public class UserInviteEntity {


    @Id
    @TableField("id")
    @Comment("主键")
    @Column(name = "id")
    private long id;

    @Column(name = "invite_user_id")
    @Comment("邀请用户id")
    @TableId("invite_user_id")
    private long inviteUserId;


    @TableField("be_invite_user_id")
    @Comment("被邀请者")
    @Column(name = "be_invite_user_id")
    @JsonSerialize(using = ToStringSerializer.class)
    private long beInviteUserId;

    @TableField("create_time")
    @Comment("创建时间")
    @Column(name = "create_time")
    private LocalDateTime createTime;


    @TableField("btc_type")
    @Comment("比特币有效用户")
    @Column(name = "btc_type")
    private int btcType;

    @TableField("vip_type")
    @Comment("比特币有效用户")
    @Column(name = "vip_type")
    private int vipType;
    @TableField("rank_type")
    @Comment("排行榜有效用户")
    @Column(name = "rank_type")
    private int rankType;
    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public static UserInviteEntity of(long id) {
        UserInviteEntity userInfoEntity = new UserInviteEntity();
        userInfoEntity.setId(id);
        userInfoEntity.setSynDb(true);
        userInfoEntity.setCreateTime(LocalDateTime.now());
        userInfoEntity.setVipType(Def.FALSE);
        userInfoEntity.setBtcType(Def.FALSE);
        return userInfoEntity;
    }

    public static UserInviteEntity ofNull() {
        UserInviteEntity userInfoEntity = new UserInviteEntity();
        return userInfoEntity;
    }

    public void setRankType(int rankType) {
        this.rankType = rankType;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getRankType, this);
    }

    public void setVipType(int vipType) {
        this.vipType = vipType;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getVipType, this);
    }

    public void setBtcType(int btcType) {
        this.btcType = btcType;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getBtcType, this);
    }

    public void setInviteUserId(long inviteUserId) {
        this.inviteUserId = inviteUserId;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getInviteUserId, this);
    }

    public void setBeInviteUserId(long beInviteUserId) {
        this.beInviteUserId = beInviteUserId;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getBeInviteUserId, this);
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserInviteEntity::getCreateTime, this);
    }


}
